package uf.audit.db;

import uf.audit.util.MD5;

import com.jfinal.plugin.activerecord.DbKit;
import com.jfinal.plugin.activerecord.Model;

/**
 * 用户表，需要在auditconfig中注册，作为数据实体使用
 * 
 * @author sunny
 *
 */
public class User extends Model<User> {
	private static final long serialVersionUID = -7644540082576539659L;
	public static User dao = new User().use(DbKit.MAIN_CONFIG_NAME);

	public User checkUser(String userName, String password) {
		User rec = null;
		if (password == null) {
			rec = User.dao
					.findFirst(
							"select top 1 * from sjuser where username=? and userpassword is null",
							userName);
		} else {
			rec = User.dao
					.findFirst(
							"select top 1 * from sjuser where username=? and userpassword=?",
							userName, MD5.getStringMD5String(password));
		}
		return rec;
	}
}
